<%@ page import="com.example.servletdemo.cons.Constance" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>登录页面异步交互</title>
  <% String path= Constance.WEBURL;%>
  <script type="text/javascript" src="https://lib.baomitu.com/jquery/3.3.1/jquery.js"></script>
<%--  <script type="text/javascript" src="<%=path%>/resources/js/jquery.min.js"></script>--%>
</head>
<body>
<form id="xx">
  <table>
    <tr>
      <td>用户名</td>
      <td><input type="text" name="name" id="username"></td>
    </tr>
    <tr>
      <td>密码</td>
      <td><input type="text" name="pwd" id="password"></td>
    </tr>
    <tr>
      <td><input type="button" value="提交" id="loginBtn" onclick="login()"></td>
    </tr>
  </table>
</form>
</body>
<script >
  function login(){
    $.ajax({
      url:"http://localhost:8080/UserLoginServlet",
      contentType: "application/json;charset=UTF-8",
      dataType: 'json',
      type: 'post',
      data: JSON.stringify({
        username:$("#username").val(),
        password: $("#password").val(),
      }),
      success:function (json){
         alert(json)
       // alert('密码错误')
      },
      error:function (e){
        // alert(e)
      }
    })
  }
</script>
</html>
